﻿using System.Text.Json.Serialization;
using Simple.Common.Helpers;

namespace Simple.Services;

public class ChildrenModel : ModelBase
{
    /// <summary>
    /// 主键
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    /// 幼儿姓名
    /// </summary>
    [Required(ErrorMessage = "幼儿姓名不能为空")]
    public string Name { get; set; } = "";

    /// <summary>
    /// 学号
    /// </summary>
    public string? StudentNumber { get; set; }

    /// <summary>
    /// 出生日期
    /// </summary>
    [Required(ErrorMessage = "出生日期不能为空")]
    public DateTime? Birthday { get; set; }

    /// <summary>
    /// 出生日期
    /// </summary>
    public string? BirthdayStr { get; set; }

    /// <summary>
    /// 年龄
    /// </summary>
    public string? Age { get; set; }

    /// <summary>
    /// 性别
    /// </summary>
    [Required(ErrorMessage = "性别不能为空")]
    public GenderType Gender { get; set; } = GenderType.Male;

    /// <summary>
    /// 家庭地址
    /// </summary>
    public string? HomeAddress { get; set; }

    /// <summary>
    /// 所在班级
    /// </summary>
    public string? ClassesId { get; set; }

    /// <summary>
    /// 所在班级
    /// </summary>
    public string? ClassName { get; set; }

    /// <summary>
    /// 登记日期
    /// </summary>
    public DateTime? RegisteredDay { get; set; }

    /// <summary>
    /// 幼儿状态
    /// </summary>
    public EnumChildState ChildState { get; set; } = EnumChildState.NotInClass;

    /// <summary>
    /// 毕业
    /// </summary>
    public DateTime? GradDay { get; set; }

    /// <summary>
    /// 入班时间
    /// </summary>
    public DateTime? ReadingDay { get; set; }

    /// <summary>
    /// 头像数据
    /// </summary>
    public string Base64str { get; set; }


    /// <summary>
    /// 家长集合
    /// </summary>
    public List<ChildParentDto> ParentList { get; set; }


    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<Childrens, ChildrenModel>()
            .ForMember(dest => dest.BirthdayStr, option => option.MapFrom(b => b.Birthday.Value.ToString("yyyy-MM-dd")))
            .ForMember(dest => dest.Age, option => option.MapFrom(b => AgeHelper.ToAgeStr(b.Birthday.Value)));

        profile.CreateMap<ChildrenModel, Childrens>();

    }

}

public class ShiftTransfersDto
{
    /// <summary>
    /// 幼儿Id
    /// </summary>
    public string? ChildId { get; set; }

    /// <summary>
    /// 班级Id
    /// </summary>
    public string? ClassesId { get; set; }
}


public class ChildParentDto
{
    /// <summary>
    /// 幼儿id
    /// </summary>
    public Guid ChildId { get; set; }


    public Guid? ParentId { get; set; }

    /// <summary>
    /// 家长名称
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 手机号码
    /// </summary>
    public string? PhoneNumber { get; set; }

    /// <summary>
    /// 与幼儿关系
    /// </summary>
    public EnumParentRelationship Relationship { get; set; }

    /// <summary>
    /// 工作单位
    /// </summary>
    public string? Workplace { get; set; }

    /// <summary>
    /// 学历
    /// </summary>
    public EnumParentDegree Degree { get; set; } = EnumParentDegree.Unknown;

    /// <summary>
    /// 是否开通微信端
    /// </summary>
    public bool IsOpenWechat { get; set; } = false;
}

public class MobileChildInfoDto : ModelBase
{
    public Guid Id { get; set; }
    public Guid? ImgId { get; set; }

    /// <summary>
    /// 幼儿姓名
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 班级名称
    /// </summary>
    public string? ClassName { get; set; }

    public string? ClassId { get; set; }

    /// <summary>
    /// 学号
    /// </summary>
    public string? StudentNumber { get; set; }

    /// <summary>
    /// 性别
    /// </summary>
    [Required(ErrorMessage = "性别不能为空")]
    public GenderType Gender { get; set; } = GenderType.Male;

    /// <summary>
    /// 性别
    /// </summary>
    public string? GenderSte { get; set; }

    /// <summary>
    /// 出生日期
    /// </summary>
    public string? BirthdayStr { get; set; }

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<Childrens, MobileChildInfoDto>()
            .ForMember(dest => dest.BirthdayStr, option => option.MapFrom(b => b.Birthday.Value.ToString("yyyy-MM-dd")))
            .ForMember(dest => dest.GenderSte, option => option.MapFrom(b => EnumHelper.GetDescriptionContent(b.Gender)));


    }
}
